package com.dh.user.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/** 
* @author 作者 dinghao
* @version 创建时间：2018年11月20日 下午4:58:51 
* @Description 类说明 :
*/
public class CookieUtil {

	
	public static void set(HttpServletResponse response,
			String name,String value,int maxAge) {
		Cookie cookie = new Cookie(name, value);
		cookie.setPath("/");
		cookie.setMaxAge(maxAge);
		response.addCookie(cookie);
	}

	public static Cookie get(HttpServletRequest request, String token) {
		Cookie[] cookies = request.getCookies();
		if (cookies != null) {
			for (Cookie cookie : cookies) {
				if(token .equals(cookie.getName())) {
					return cookie;
				}
			}
		}
		return null;
	}
}
